#coding=utf-8
'''
Matching Strings Using Shell Wildcard Patterns:
from fmatch import fnmatch, fnmatchcase
'''

from fnmatch import fnmatch, fnmatchcase
a = fnmatch('too.txt', '*.txt')
b = fnmatch('foo.txt', '?oo.txt')
c = fnmatch('Dat45.csv', 'Dat[0-9]*')
print(a)
print(b)
print(c)

names = ['Dat1.csv', 'Dat2.csv', 'config.ini', 'foo.py']
# 选以Dat开头的csv文件
d = [name for name in names if fnmatch(name, 'Dat*.csv')]
print(d)

# fnmatch是否区分大小写 与 本机操作系统一致
e = fnmatch('foo.txt', '*.TXT')
print(e)
f = fnmatchcase('foo.txt', '*.TXT')
print(f)

addresses = [
    '5412 N CLARK ST',
    '1060 W ADDISON ST',
    '1039 W GRANVILLE AVE',
    '2122 N CLARK ST',
    '4802 N BROADWAY',
]

# 以ST结尾的
g = [address for address in addresses if fnmatch(address, '*ST')]
# 54开头 包含CLARK
h = [address for address in addresses if fnmatchcase(address, '54[0-9][0-9] *CLARK*')]
print(g)
print(h)